<?php
/**
 * 文章/专题最新页（统计）
 * Create on 2015-07-08 14:55:36
 * Create by yuebin
 */
namespace haibao\cms\business\control\pc\newlist;
use haibao\cms\model\filter\Article as ArticleFilter;
use haibao\cms\model\filter\FeaturePublish as FeaturePublishFitler;
use haibao\frame\data\query\Condition;

class ListController extends \haibao\cms\business\control\pc\channel\ChannelController{
	
	CONST ARTICLE_TAG = 7159;
	CONST FEATURE_TAG = 11037; 
	public function __construct($updateTime = null,$controlId,$isPublish){
		parent::__construct($updateTime,$controlId,$isPublish);
	}
	
	
	/**
	 * 获取模版内容
	 * @param : String $content
	 */
	public function displayTemplateHtml(){

		$controlData = $this->getParameter(self::$CONTROL_DATA);
		$content = $this->getParameter(self::$CONTROL_CONTENT);
		
		$channelTagId = $this->getParameter(self::$SITE_CHANNEL_TAG);
		if($channelTagId == self::ARTICLE_TAG){
			$type = 1;
			$this->assign('haibaoUrl',\haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HAIBAO_URL).'/article/');
			$this->getArticleList();
		}else{

			$type = 2;
			$this->getFeatureList();
		}
		$this->assign('type',$type);
		
		$path = $this->generateHtmlPath(__CLASS__);
		$this->generateHtml($path,$content);
		return $this->getHtml($path);
	}
	
	/**
	 * 获取文章列表
	 */
	private function getArticleList(){
		
		$articleFilter = new ArticleFilter();
		$articleFilter->select(array(
				ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,
				ArticleFilter::CONDITION_FIELD_NAME_TITLE,
				ArticleFilter::CONDITION_FIELD_NAME_ARTICLE_PUBLISHID,
		));
		$articleFilter->limit(0,20);
		$articleFilter->order(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHTIME,false);
		$articleFilter->where(ArticleFilter::CONDITION_FIELD_NAME_PUBLISHED,Condition::CONDITION_EQUAL,\haibao\cms\model\data\Article::PUBLISHED_YES);
		$list = \haibao\cms\business\Article::getArticleList($articleFilter);
		$this->assign('list',$list);
	}
	
	/**
	 * 获取专题列表
	 */
	private function getFeatureList(){
		
		$featurePublishFilter = new FeaturePublishFitler();
		$featurePublishFilter->select(array(
				FeaturePublishFitler::CONDITION_FIELD_NAME_FEATURE_NAME,
				FeaturePublishFitler::CONDITION_FIELD_NAME_PUBLISH_TIME,
				FeaturePublishFitler::CONDITION_FIELD_NAME_URL,
		));
		$featurePublishFilter->limit(0,20);
		$featurePublishFilter->order(FeaturePublishFitler::CONDITION_FIELD_NAME_PUBLISH_TIME,false);
		$featurePublishFilter->where(FeaturePublishFitler::CONDITION_FIELD_NAME_STATUS,Condition::CONDITION_EQUAL,\haibao\cms\model\data\FeaturePublish::STATUS_PUBLISH);
		$featurePublishFilter->where(FeaturePublishFitler::CONDITION_FIELD_NAME_IS_H5,Condition::CONDITION_EQUAL,0);
		
		$defineFilter = new \haibao\cms\model\filter\FeatureDefine();
		$defineFilter->select(array(
				\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_FEATURE_NAME,
		));
		$featurePublishFilter->innerJoin(
				$defineFilter,
				null,
				\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE_ID,
				\haibao\cms\model\filter\FeatureDefine::CONDITION_FIELD_NAME_ID,
				\haibao\cms\model\filter\FeaturePublish::CONDITION_FIELD_NAME_FEATURE_DEFINE,
				false
		);
		
		$list = \haibao\cms\business\FeaturePublish::getAllDynamicDefineList($featurePublishFilter);
		$this->assign('list',$list);
		
	}
}